<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  let Tool = {
    max(key) {
      let i = this.data.sort((a, b) => b[key] - a[key])[0];
      console.log(i);
    }
  };
  class Lesson {
    constructor(lessons) {
      this.lessons = lessons;
    }
    get data() {
      return this.lessons;
    }
  };

  const data = [{
    name: "js",
    price: 20
  }, {
    name: "mysql",
    price: 30
  }, {
    name: "mongodb",
    price: 100
  }];

  Object.assign(Lesson.prototype, Tool); //核心就是往原型中添加方法

  let hd = new Lesson(data);
  console.dir(hd);
  hd.max("price")
</script>

</html>